package com.li.service;

import com.li.dao.UserProjectMapper;
import com.li.model.UserProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
public class UserProjectServiceImpl implements UserProjectService {
    @Autowired
    private UserProjectMapper projectMapper;
    @Override
    public List<UserProject> queryAllByUid(long uid) {
        return projectMapper.queryAllByUid(uid);
    }

    @Override
    public void addProject(UserProject userProject) {
        userProject.setCreateTime(new Date());
        projectMapper.addProject( userProject);
    }

    @Override
    public Optional<UserProject> queryProjectById(long id) {
        UserProject project = this.projectMapper.queryProjectById(id);
        if (project == null){
            return Optional.empty();
        }
        return Optional.of(project);
    }

    @Override
    public void updateProject(UserProject userProject) {
        userProject.setUpdateTime(new Date());
        projectMapper.updateProject(userProject);
    }

    @Override
    public void deleteProject(long id) {
        projectMapper.deleteProject(id);
    }
}
